package com.yc.yyds.servlet;

import com.yc.yyds.Bean.Result;
import com.yc.yyds.biz.BizException;
import com.yc.yyds.biz.SaveIndentBiz;
import com.yc.yyds.util.ToJsonUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Map;

/**
 * 余额支付
 */
@WebServlet(name = "MoneyPayServlet", value = "/MoneyPayServlet.s")
public class MoneyPayServlet extends HttpServlet {
    SaveIndentBiz biz =new SaveIndentBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String,Object> userMsg = (Map<String, Object>) request.getSession().getAttribute("userMsg");
        String payway = request.getParameter("payway");
        String indentid = request.getParameter("indentid");
        String userid = request.getParameter("userid");
        String ppjhid = request.getParameter("ppjhid");
        String num = request.getParameter("num");
        String money = request.getParameter("money");
        String balance = request.getParameter("balance");
        Result result;
        //余额支付
        try {
            biz.queren(userid,ppjhid,num,balance,money,indentid,payway);
            result = new Result(1,"支付成功",null);
            userMsg.put("money",Float.parseFloat(balance)-Float.parseFloat(money));
            request.getSession().setAttribute("userMsg",userMsg);
            ToJsonUtil.toJson(response,result);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(1,e.getMessage(),null);
            ToJsonUtil.toJson(response,result);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
